from typing import List, Dict
import httpx
from app.config import settings


async def fetch_weibo_keyword_series(keyword: str) -> List[Dict]:
    if not settings.WEIBO_API_BASE or not settings.WEIBO_ACCESS_TOKEN:
        return []
    url = f"{settings.WEIBO_API_BASE}/search/series"
    headers = {"Authorization": f"Bearer {settings.WEIBO_ACCESS_TOKEN}"}
    params = {"q": keyword}
    async with httpx.AsyncClient(timeout=10) as client:
        resp = await client.get(url, headers=headers, params=params)
        resp.raise_for_status()
        data = resp.json()
    return data.get("series", [])


async def fetch_weibo_account_metrics(account_id: str) -> Dict:
    if not settings.WEIBO_API_BASE or not settings.WEIBO_ACCESS_TOKEN:
        return {}
    url = f"{settings.WEIBO_API_BASE}/accounts/{account_id}/metrics"
    headers = {"Authorization": f"Bearer {settings.WEIBO_ACCESS_TOKEN}"}
    async with httpx.AsyncClient(timeout=10) as client:
        resp = await client.get(url, headers=headers)
        resp.raise_for_status()
        data = resp.json()
    return data or {}
